import 'package:fate_blind_box/routes/page_route_names.dart';
import 'package:fate_blind_box/theme/theme_color.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../im/chatPage.dart';
import '../../utils/default/Empty.dart';

class ProfileInfo extends StatefulWidget {
  final Map userInfo;

  const ProfileInfo({Key? key, required this.userInfo}) : super(key: key);

  @override
  State<ProfileInfo> createState() => _ProfileInfoState();
}

class _ProfileInfoState extends State<ProfileInfo> {
  String homeAddr = ' ';
  String incomeValNew =  ' ';
  String hasCar = ' ';
  String hasHome = ' ';
  String liveAddress = '';
  int maritalStatus =0;
  int childNum =0;
  int edu = 0;
  String occipation = '职业：';
  num mcageStart = 24;
  num mcageEnd =  32;
  num mcweightStart = 60;
  num mcweightEnd = 80;
  num mcheightStart = 175;
  num mcheightEnd = 180;
  String mcEduNew = '学历';
  String mcIncomeNew ='薪资';
  String mcsbuychase = '无房';
  String mcsbuyCarNew = '无车';
  @override
  Widget build(BuildContext context) {
    double screenWidth = MediaQuery.of(context).size.width;


    return Stack(
      children: [
        Container(
          padding: const EdgeInsets.fromLTRB(20, 20, 20, 50),
          child: widget.userInfo == null
              ? const Empty()
              : SingleChildScrollView(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        "基本资料",
                        style: TextStyle(
                            color: ThemeColor.textColor,
                            fontSize: 14,
                            fontWeight: FontWeight.bold),
                      ),
                      const SizedBox(
                        height: 10,
                      ),
                      Row(
                        children: [
                          _buildInfoItemView(
                            widget.userInfo['age'] == null
                                ? ' '
                                : widget.userInfo['age'].toString() + '岁',
                          ),
                          const SizedBox(
                            width: 12,
                          ),
                          _buildInfoItemView(widget.userInfo['height'] == null
                              ? '0cm'
                              : widget.userInfo['height'].toString() + 'cm'),
                          const SizedBox(
                            width: 12,
                          ),
                          _buildInfoItemView(widget.userInfo['weight'] == null
                              ? '0kg'
                              : widget.userInfo['weight'].toString() + 'kg'),
                        ],
                      ),

                      const SizedBox(
                        height: 10,
                      ),
                      Row(
                        children: [
                          _buildInfoItemView('现居地:' + liveAddress),
                          const SizedBox(
                            width: 12,
                          ),
                          Expanded(child: _buildInfoItemView('家乡:' + homeAddr)),
                          const SizedBox(
                            width: 12,
                          ),
                        ],
                      ),
                      const SizedBox(
                        height: 10,
                      ),
                      Row(
                        children: [
                          _buildInfoItemView(getMarryStatus(maritalStatus)),
                          const SizedBox(
                            width: 12,
                          ),
                          _buildInfoItemView(childNum.toString()+'个孩子'),
                          const SizedBox(
                            width: 12,
                          ),
                        ],
                      ),
                      const SizedBox(
                        height: 10,
                      ),
                      Row(
                        children: [
                          _buildInfoItemView(getEduStatus(edu)),
                          const SizedBox(
                            width: 12,
                          ),
                          _buildInfoItemView(occipation),
                        ],
                      ),
                      const SizedBox(
                        height: 10,
                      ),
                      Row(
                        children: [
                          _buildInfoItemView("年薪" + incomeValNew),
                         const SizedBox(
                            width: 12,
                          ),
                          _buildInfoItemView(hasHome),
                          const SizedBox(
                            width: 12,
                          ),
                          _buildInfoItemView(hasCar),

                        ],
                      ),
                      const SizedBox(
                        height: 10,
                      ),
                      Text(
                        "择偶要求",
                        style: TextStyle(
                            color: ThemeColor.textColor,
                            fontSize: 14,
                            fontWeight: FontWeight.bold),
                      ),
                      const SizedBox(
                        height: 10,
                      ),
                      Wrap(
                        spacing: 12,
                        runSpacing: 14,
                        children: [
                           _buildInfoChooseItemView(imgStr:'images/user/zobz_age_icon.png',value:mcageStart.toString()+'岁'+'-'+mcageEnd.toString()+'岁',),
                          _buildInfoChooseItemView(imgStr:'images/user/zobz_tz_icon.png',value:mcweightStart.toString()+'kg'+'-'+mcweightEnd.toString()+'kg',),
                          _buildInfoChooseItemView(imgStr:'images/user/zobz_height_icon.png',value:mcheightStart.toString()+'cm'+'-'+mcheightEnd.toString()+'cm',),
                          _buildInfoChooseItemView(imgStr:'images/user/zobz_edu_icon.png',value:mcEduNew,),
                          _buildInfoChooseItemView(imgStr:'images/user/zobz_salary_icon.png',value:mcIncomeNew,),
                          //_buildInfoChooseItemView(imgStr:'images/user/zobz_edu_icon.png',value:mcsbuyCarNew,),
                          //_buildInfoChooseItemView(imgStr:'images/user/zobz_salary_icon.png',value:mcsbuychase,),
                        ],
                      ),





                      const SizedBox(
                        height: 20,
                      ),
                    ],
                  ),
                ),
        ),

        // Expanded(child: SizedBox()),
        Align(
          alignment: Alignment.bottomCenter,
          child: GestureDetector(
            onTap: () {
              if (widget.userInfo['easeuserId'] != null) {
                Get.toNamed(PageRouteNames.messageChat, arguments: {
                  'nickName': widget.userInfo['nickName'],
                  'id': widget.userInfo['easeuserId'].toString(),
                });
              }
              // Navigate.toPage(const DownloadAppUi());
            },
            child: Container(
              margin: const EdgeInsets.only(bottom: 30),
              height: 40,
              width: screenWidth - 40,
              alignment: Alignment.center,
              decoration: ShapeDecoration(
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(20)),
                color: ThemeColor.appColor,
              ),
              child: const Text(
                "聊天",
                style: TextStyle(color: Colors.white),
              ),
            ),
          ),
        )
      ],
    );
  }

  Widget _buildInfoItemView(String value) {
    return Container(
        height: 31,
        padding: const EdgeInsets.only(left: 12,right: 12),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(16),
          color: const Color.fromRGBO(127, 105, 217, 0.05),
        ),
        alignment: Alignment.center,
        child: Text(
          value,
          style: TextStyle(fontSize: 14, color: ThemeColor.appColor),
        ));
  }
  //择偶要求
  Widget _buildInfoChooseItemView({String imgStr='',String value=''}) {
    return Container(
        height: 31,
        padding: const EdgeInsets.only(left: 12,right: 12),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(16),
          color:const Color(0xFFF5F5F5),
        ),
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Image.asset(imgStr,width: 14,height: 14,),
            const SizedBox(width: 4,),
            Text(
              value,
              style: TextStyle(fontSize: 14, color: ThemeColor.black1414Color),
            ),
          ],
        ));
  }

  String getMarryStatus(int status) {
    String statusStr = '婚姻未知';
    switch (status) {
      case 0:
        statusStr = '单身';
        break;
      case 1:
        statusStr = '已婚';
        break;
      case 2:
        statusStr = '再婚';
        break;
      case 3:
        statusStr = '离异';
        break;
      case 4:
        statusStr = '丧偶';
        break;
    }
    return statusStr;
  }

  String getEduStatus(int status) {
    String statusStr = '学历未知';
    switch (status) {
      case 0:
        statusStr = '小学';
        break;
      case 1:
        statusStr = '初中';
        break;
      case 2:
        statusStr = '高中';
        break;
      case 3:
        statusStr = '大专';
        break;
      case 4:
        statusStr = '本科';
        break;
      case 5:
        statusStr = '硕士';
        break;
      case 6:
        statusStr = '博士';
        break;
      case 7:
        statusStr = '教授';
        break;
    }
    return statusStr;
  }


  @override
  void initState() {
    super.initState();
    if(widget.userInfo!=null){
      initData();
    }
  }

  void initData(){
     homeAddr = widget.userInfo['homeAddr'] ?? ' ';
     incomeValNew = widget.userInfo['incomeValNew'] ?? ' ';
     hasCar = widget.userInfo['buyCarNew'] ?? '无车';
     hasHome = widget.userInfo['buychaseNew'] ?? '无房';
     liveAddress = widget.userInfo['liveAddress'] ?? '';
     maritalStatus =widget.userInfo['maritalStatus'] ??0;
     childNum =widget.userInfo['childNum'] ??0;
     edu = widget.userInfo['edu'] ?? 0;
     occipation = widget.userInfo['occipation'] ?? '职业：';
     mcageStart = widget.userInfo['mcsageStartNew'] ?? 24;
     mcageEnd = widget.userInfo['mcsageEndNew'] ?? 32;
     mcweightStart = widget.userInfo['mcsweightStartNew']??60;
     mcweightEnd = widget.userInfo['mcsweightEndNew']??80;
     mcheightStart = widget.userInfo['mcsheightStartNew']??175;
     mcheightEnd = widget.userInfo['mcsheightEndNew']??180;
     mcEduNew = widget.userInfo['cmseduNew'] ?? '学历';
     mcIncomeNew = widget.userInfo['mcsincomeValNew']?? '薪资';
  }

}
